package com.ruoyi.project.app.utils;

import com.ruoyi.common.utils.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexValidate {

    private static final String emailRegex = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    private static final String phoneRegex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(16[0-9])|(17[013678])|(18[0,5-9]))\\d{8}$";

    public static boolean validationEmail(String email){
        boolean flag = false;
        if(StringUtils.isNotBlank(email)){
            Pattern pattern = Pattern.compile(emailRegex);
            Matcher matcher = pattern.matcher(email);
            flag = matcher.matches();
        }
        return flag ;
    }

    public static boolean validationPhone(String phone){
        boolean flag = false;
        if(StringUtils.isNotBlank(phone)){
            Pattern pattern = Pattern.compile(phoneRegex);
            Matcher matcher = pattern.matcher(phone);
            flag = matcher.matches();
        }
        return flag ;
    }

    public static void main(String[] args) {
        System.out.println(validationEmail("2329880458@qq.com"));
        System.out.println(validationEmail("2329880458qq.com"));
        System.out.println(validationPhone("13576813106"));
        System.out.println(validationPhone("166751915301"));
    }

}
